package logic

import (
	"context"
	"rpc/model/mysql"

	"rpc/internal/svc"
	"rpc/pb/house"

	"github.com/zeromicro/go-zero/core/logx"
)

type ListHouseLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewListHouseLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ListHouseLogic {
	return &ListHouseLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ListHouseLogic) ListHouse(in *house.ListHouseRequest) (*house.ListHouseResponse, error) {
	// todo: add your logic here and delete this line
	var houses []mysql.House
	mysql.DB.Find(&houses)

	var ListHouses []*house.ListHouse
	for _, m := range houses {
		list := &house.ListHouse{
			HouseTitle:   m.HouseTitle,
			HousePrice:   float32(m.HousePrice),
			HouseImg:     m.HouseImg,
			HouseAddress: m.HouseAddress,
			HouseArea:    float32(m.HouseArea),
		}
		ListHouses = append(ListHouses, list)
	}

	return &house.ListHouseResponse{List: ListHouses}, nil
}
